import Immutable from 'seamless-immutable';
import * as types from '../constants/ActionTypes';
import helper from '../helper/testResultHelper.js';

const testResult = Immutable.from({
  resultData: {},
  resultList: [],
  detailData: {},
  oneDetailInfo: { data:{} },
  saveMsg: {}
});
export default function testResultReducer(state = testResult, action) {
  const { payload, type } = action;
  switch (type) {
    case types.FETCH_TEST_RESULT:
      return state.setIn(['resultData'], payload)
        .setIn(['resultList'], payload.data);
    case types.UPDATE_ONE_TEST_RESULT:
      return state.setIn(['resultList'], helper.updataOne(state.resultList, payload))
        .setIn(['oneDetailInfo'], payload);
    case types.FETCH_RESULT_DETAIL:
      return state.setIn(['detailData'], payload);
    case types.RESTORE_TEST_CATEGORY:
      return state.setIn(['testResultList'], {});
    default:
      return state;
  }
}
